package com.starblink.basic.log

import android.content.Context

/**
 * 日志模块
 * 默认用微信mars-xlog实现
 */
object SKLogger {

    private const val TAG = "SKLogger"

    private lateinit var logger: ISKLogger

    @JvmStatic
    fun initLog(context: Context) {
        val marsLogEnable = true
        if (marsLogEnable) {
            logger = try {
                MarsXLogMgr.initXLog(context)
                MarsLogImp()
            } catch (e: Throwable) {
                android.util.Log.e(TAG, "XLog init exception", e)
                DefaultLoggerImp()
            }
        } else {
            logger = DefaultLoggerImp()
        }
    }


    @JvmStatic
    fun v(tag: String, msg: String) {
        logger.v(tag, msg)
    }


    @JvmStatic
    fun d(tag: String, msg: String) {
        logger.d(tag, msg)
    }


    @JvmStatic
    fun e(tag: String, msg: String) {
        logger.e(tag, msg)
    }

    @JvmStatic
    fun e(tag: String, msg: String, show: Boolean) {
        if (show) {
            logger.e(tag, msg)
        }
    }

    @JvmStatic
    fun i(tag: String, msg: String) {
        logger.i(tag, msg)
    }


    @JvmStatic
    fun w(tag: String, msg: String) {
        logger.w(tag, msg)
    }


    @JvmStatic
    fun wtf(tag: String, msg: String, tr: Throwable?) {
        logger.wtf(tag, msg, tr)
    }


    @JvmStatic
    fun flushLog() {
        logger.flushLog()
    }
}